<!--_meta 作为公共模版分离出去-->
<!DOCTYPE HTML>
<html>

<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="Bookmark" href="/favicon.ico">
    <link rel="Shortcut Icon" href="/favicon.ico" />
    <!--[if lt IE 9]>
<script type="text/javascript" src="/admin/lib/html5shiv.js"></script>
<script type="text/javascript" src="/admin/lib/respond.min.js"></script>
<![endif]-->
    <link rel="stylesheet" type="text/css" href="/admin/static/h-ui/css/H-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="/admin/static/h-ui.admin/css/H-ui.admin.css" />
    <link rel="stylesheet" type="text/css" href="/admin/lib/Hui-iconfont/1.0.8/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="/admin/static/h-ui.admin/skin/default/skin.css" id="skin" />
    <link rel="stylesheet" type="text/css" href="/admin/static/h-ui.admin/css/style.css" />
    <!--[if IE 6]>
<script type="text/javascript" src="/admin/lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
    <!--/meta 作为公共模版分离出去-->
    <title>修改用户 - H-ui.admin v3.1</title>
    <meta name="keywords" content="H-ui.admin v3.1,H-ui网站后台模版,后台模版下载,后台管理系统模版,HTML后台模版下载">
    <meta name="description" content="H-ui.admin v3.1，是一款由国人开发的轻量级扁平化网站后台模板，完全免费开源的网站后台管理系统模版，适合中小型CMS后台系统。">
</head>

<body>
    <article class="page-container">
        <form action="" method="post" class="form form-horizontal" id="form-member-add" enctype="multipart/form-data">
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>用户名：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" value="{{$data[0] -> username}}" placeholder="" id="username" name="username">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>性别：</label>
                <div class="formControls col-xs-8 col-sm-9 skin-minimal">
                    <div class="radio-box">
                        <input name="gender" type="radio" value="1" id="gender-1" @if($data[0] -> gender == '1') checked @endif >
                        <label for="gender-1">男</label>
                    </div>
                    <div class="radio-box">
                        <input type="radio" id="gender-2" value="2" name="gender" @if($data[0] -> gender == '2') checked @endif >
                        <label for="gender-2">女</label>
                    </div>
                    <div class="radio-box">
                        <input type="radio" id="gender-3" value="3" name="gender" @if($data[0] -> gender == '3') checked @endif >
                        <label for="gender-3">保密</label>
                    </div>
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>手机：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" value="{{$data[0] -> mobile}}" placeholder="" id="mobile" name="mobile">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>邮箱：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" value="{{$data[0] -> email}}" placeholder="@" name="email" id="email">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3">头像：</label>
                <div class="formControls col-xs-8 col-sm-9"> 
                    <!--dom结构部分-->
                    <div id="uploader-demo">
                        <!--用来存放item-->
                        <div id="fileList" class="uploader-list"><img src="{{$data[0] -> avatar}}" width="90"></div>
                        <!-- <div id="filePicker">选择图片</div> -->
                        <!-- 隐藏域用来保存图片地址 -->
                        <input type="hidden" name="avatar" id="avatar" value="">
                    </div>
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>类型：</label>
                <div class="formControls col-xs-8 col-sm-9 skin-minimal">
                    <div class="radio-box">
                        <input name="type" type="radio" value="1" id="type-1"  @if($data[0] -> type == '1') checked @endif >
                        <label for="type-1">学生</label>
                    </div>
                    <div class="radio-box">
                        <input type="radio" id="type-2" value="2" name="type"  @if($data[0] -> type == '2') checked @endif >
                        <label for="type-2">老师</label>
                    </div>
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>状态：</label>
                <div class="formControls col-xs-8 col-sm-9 skin-minimal">
                    <div class="radio-box">
                        <input name="status" type="radio" value="2" id="status-1"  @if($data[0] -> status == '2') checked @endif >
                        <label for="status-1">已启用</label>
                    </div>
                    <div class="radio-box">
                        <input type="radio" id="status-2" value="1" name="status" @if($data[0] -> status == '1') checked @endif >
                        <label for="status-2">已禁用</label>
                    </div>
                </div>
            </div>
            {{csrf_field()}}
            <div class="row cl">
                <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                    <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
                </div>
            </div>
        </form>
    </article>
    <!--_footer 作为公共模版分离出去-->
    <script type="text/javascript" src="/admin/lib/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript" src="/admin/lib/layer/2.4/layer.js"></script>
    <script type="text/javascript" src="/admin/static/h-ui/js/H-ui.min.js"></script>
    <script type="text/javascript" src="/admin/static/h-ui.admin/js/H-ui.admin.js"></script>

    <!-- 引入webuploader相关外部文件 -->
    <link rel="stylesheet" type="text/css" href="/admin/lib/webuploader-0.1.5/webuploader.css">
    <script type="text/javascript" src="/admin/lib/webuploader-0.1.5/webuploader.js"></script>

    <!--/_footer 作为公共模版分离出去-->
    <!--请在下方写此页面业务相关的脚本-->
    <script type="text/javascript" src="/admin/lib/My97DatePicker/4.8/WdatePicker.js"></script>
    <script type="text/javascript" src="/admin/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
    <script type="text/javascript" src="/admin/lib/jquery.validation/1.14.0/validate-methods.js"></script>
    <script type="text/javascript" src="/admin/lib/jquery.validation/1.14.0/messages_zh.js"></script>
    <script type="text/javascript">
    jQuery(function() {
        var $ = jQuery,
        $list = $('#fileList'),
        // 优化retina, 在retina下这个值是2
        ratio = window.devicePixelRatio || 1,

        // 缩略图大小
        thumbnailWidth = 100 * ratio,
        thumbnailHeight = 100 * ratio,

        // Web Uploader实例
        uploader;

        // 初始化Web Uploader
        uploader = WebUploader.create({
            // 自己主动携带的参数定义
            formData:{
                _token:"{{csrf_token()}}",//添加值
            },
            // 自动上传。
            auto: true,
            // swf文件路径
            swf: '/admin/lib/webuploader-0.1.5/Uploader.swf',
            // 文件接收服务端。(路由)
            // server: '/admin/uploader/webuploader',
            server: '/admin/uploader/qiniu',

            // 选择文件的按钮。可选。
            // 内部根据当前运行是创建，可能是input元素，也可能是flash.
            pick: '#filePicker',

            // 只允许选择文件，可选。
            accept: {
                title: 'Images',
                extensions: 'gif,jpg,jpeg,bmp,png',
                mimeTypes: 'image/gif,image/png,image/jpeg'
            }
        });

        // 当有文件添加进来的时候
        uploader.on( 'fileQueued', function( file ) {
            var $li = $(
                '<div id="' + file.id + '" class="file-item thumbnail">' +
                '<img>' +
                '<div class="info">' + file.name + '</div>' +
                '</div>'
                ),
            $img = $li.find('img');
            // 移除之前全部图片
            $('.thumbnail').remove();
            $list.append( $li );

            // 创建缩略图
            uploader.makeThumb( file, function( error, src ) {
                if ( error ) {
                    $img.replaceWith('<span>不能预览</span>');
                    return;
                }
                $img.attr( 'src', src );
            }, thumbnailWidth, thumbnailHeight );
        });

        // 文件上传过程中创建进度条实时显示。
        uploader.on( 'uploadProgress', function( file, percentage ) {
            var $li = $( '#'+file.id ),
            $percent = $li.find('.progress span');

            // 避免重复创建
            if ( !$percent.length ) {
                $percent = $('<p class="progress"><span></span></p>')
                .appendTo( $li )
                .find('span');
            }

            $percent.css( 'width', percentage * 100 + '%' );
        });

        // 文件上传成功，给item添加成功class, 用样式标记上传成功。
        // response 表示ajax返回值，如果是json格式，可以直接使用
        uploader.on( 'uploadSuccess', function( file,response ) {
            // 将返回值写入列表表单
            if(response.errorCode == '0'){
                $('#avatar').val(response.path);
                layer.msg(response.message,{icon:1,time:1000});
            }else{
                layer.msg(response.message,{icon:2,time:1000});
            }
            $( '#'+file.id ).addClass('upload-state-done');
        });

        // 文件上传失败，现实上传出错。
        uploader.on( 'uploadError', function( file ) {
            var $li = $( '#'+file.id ),
            $error = $li.find('div.error');

            // 避免重复创建
            if ( !$error.length ) {
                $error = $('<div class="error"></div>').appendTo( $li );
            }

            $error.text('上传失败');
        });

        // 完成上传完了，成功或者失败，先删除进度条。
        uploader.on( 'uploadComplete', function( file ) {
            $( '#'+file.id ).find('.progress').remove();
        });
    });


    $(function() {
        // 四联第一联
        $('select[name=country_id]').change(function(){
            // 获取当前值
            var country_id = $(this).val();
            // 发送ajax请求获取该国家的下属的内容
            // $.get(url,data,function,datatype);
            $.get('/admin/member/getAreasByPid',{pid:country_id},function(data){
                // 获取数据进行组装
                // 循环得到全部需要追加的option
                var ops = '';
                $.each(data,function(key,value){
                    ops += "<option value='" + value.id + "'" +  '' + ">" + value.area + "</option>";
                    console.log(value);
                });
                // 先清除以前的老数据
                $('select[name=province_id]').find('option:gt(0)').remove();
                $('select[name=city_id]').find('option:gt(0)').remove();
                $('select[name=county_id]').find('option:gt(0)').remove();
                // 追加数据到ops
                $('select[name=province_id]').append(ops);
            },'json');
            // layer.alert(country_id);
        });


        // 四联第二联
        $('select[name=province_id]').change(function(){
            // 获取当前值
            var province_id = $(this).val();
            // 发送ajax请求获取该国家的下属的内容
            // $.get(url,data,function,datatype);
            $.get('/admin/member/getAreasByPid',{pid:province_id},function(data){
                // 获取数据进行组装
                // 循环得到全部需要追加的option
                var ops = '';
                $.each(data,function(key,value){
                    ops += "<option value='" + value.id + "'>" + value.area + "</option>"
                    console.log(value);
                });
                // 先清除以前的老数据
                $('select[name=city_id]').find('option:gt(0)').remove();
                $('select[name=county_id]').find('option:gt(0)').remove();
                // 追加数据到ops
                $('select[name=city_id]').append(ops);
            },'json');
            // layer.alert(country_id);
        });



        // 四联第三联
        $('select[name=city_id]').change(function(){
            // 获取当前值
            var city_id = $(this).val();
            // 发送ajax请求获取该国家的下属的内容
            // $.get(url,data,function,datatype);
            $.get('/admin/member/getAreasByPid',{pid:city_id},function(data){
                // 获取数据进行组装
                // 循环得到全部需要追加的option
                var ops = '';
                $.each(data,function(key,value){
                    ops += "<option value='" + value.id + "'>" + value.area + "</option>";
                    console.log(value);
                });
                // 先清除以前的老数据
                $('select[name=county_id]').find('option:gt(0)').remove();
                // 追加数据到ops
                $('select[name=county_id]').append(ops);
            },'json');
            // layer.alert(country_id);
        });

        $('.skin-minimal input').iCheck({
            checkboxClass: 'icheckbox-blue',
            radioClass: 'iradio-blue',
            increaseArea: '20%'
        });

        $("#form-member-add").validate({
            rules: {
                username: {
                    required: true,
                    minlength: 2,
                    maxlength: 16
                },
                gender: {
                    required: true,
                },
                mobile: {
                    required: true,
                    // isMobile: true,
                },
                email: {
                    required: true,
                    email: true,
                }
            },
            onkeyup: false,
            focusCleanup: true,
            success: "valid",
            submitHandler: function(form) {
                $(form).ajaxSubmit({
                    type: 'post',
                    url: "",
                    success: function(data) {
                    	if(data == '1'){
                    		layer.msg('添加成功!', { icon: 1, time: 1000 },function(){
                    			var index = parent.layer.getFrameIndex(window.name);
				                //parent.$('.btn-refresh').click();
                                window.parent.location.reload();
				                parent.layer.close(index);

                    		});
                    	}else{
                    		layer.msg('添加失败!', { icon: 2, time: 1000 });
                    	}
                    },
                    error: function(XmlHttpRequest, textStatus, errorThrown) {
                        layer.msg('error!', { icon: 1, time: 1000 });
                    }
                });
            }
        });
    });
    </script>
    <!--/请在上方写此页面业务相关的脚本-->
</body>

</html>